import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
import axios from 'axios'

export const useJokerStore = defineStore('joke', () => {
  const joke = ref('狐狸很容易摔跤,因为狡猾')

  const refreshJoke = async () => {
    // 调用接口获取笑话
    // axios 调用笑话接口,获取到笑话之后,更改 joke.value
    const res = await axios.get('https://api-vue-base.itheima.net/api/joke')
    joke.value = res.data
  }

  return { joke, refreshJoke }
})
